<%= javascript_include_tag "sharing.js" -%>
<%= javascript_include_tag 'link_adder.js'-%>

<h1>New Data Extract<%= render :partial=>"layouts/sandbox_warning" %></h1>

<div class="show_basic">
  <% form_tag({:action => :create}, :multipart => true) do -%>
    <%= error_messages_for :archive -%>

    <%#= hidden_field_tag 'var_hash', params[:var_hash] %>
    <%# @all_variables_array.each do |val| %>
      <%#= hidden_field_tag "all_variables_array[]", val %>
    <%# end %>

    <center>
      <div style="width: 90%;">

        <p style="margin-top: 1.5em;">
          <b>Title:</b><font style="color: #FF0000;">*</font><br/>
          <% archive_title_value = (params[:archive].blank? || params[:archive][:title].blank?) ? nil : params[:archive][:title]-%>
          <%= text_field_tag 'archive[title]', archive_title_value, :style => "width: 100%;" -%>
        </p>

        <p style="margin-top: 0.5em;">
          <b>Description:</b><br/>
          <% archive_description_value = (params[:description].blank?) ? nil : params[:description] -%>
          <%= text_area_tag 'archive[description]', archive_description_value, :style => "width: 100%;", :rows => 5 -%>
        </p>
		<h2>Data Extract will be automatically linked with the surveys that its variables are from</h2>
		<div>
			<p>          
				<b>Link with Data Extracts:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "data_extracts", :resource_type => "Data Extracts",   # this is only for presentation, not for any processing
		      :collection=>@archives,:selected=>@selected_archives,:authorization_for_showing_already_done => false } -%>
		</p>
		</div>
		<br/>
		<div style="clear:both;">
			</div>
		<div>
			<p>          
				<b>Link with Scripts:</b>
			<%= render :partial => "assets/link_selector", :locals => { :resource_id => "scripts", :resource_type => "Scripts",   # this is only for presentation, not for any processing
		      :collection=>@scripts,:selected=>@selected_scripts,:authorization_for_showing_already_done => false } -%>
		</p>
		</div>
		<br/>
        <div style="clear:both;">
        </div>
        <div>
          <p>
            <b>Link with Publications:</b>
            <%= render :partial => "assets/link_selector", :locals => { :resource_id => "publications", :resource_type => "Publications",   # this is only for presentation, not for any processing
           :collection=>@publications,:selected=>@selected_publications,:authorization_for_showing_already_done => true } -%>
          </p>
        </div>
		<br/>
		<div style="clear:both;">
			</div>
        <!-- <p style="margin: 0;"> -->
         <%#= render :partial => "linked_scripts_form", :locals => {:person => current_user, :existing_script_links => [],
         :script_suggestions => Script.get_all_as_json(current_user) } -%>
        <!-- </p> -->
      </div>
    </center>

    <center>
      <div style="width: 90%;">

        <p style="margin: 2.5em 0 0 0;">
	        <p style="margin: 2.5em 0 0 0;">
	          <%= render :partial => "assets/sharing_form", :locals => { :groups => @groups, :selected_groups => [] } -%>
	        </p>
        </p>

        <p style="margin: 0;">
          <%= render :partial => "assets/attribution_form", :locals => { :resource_type => "Data Extract",  # this is only for presentation, not for any processing
            :existing_attributions => [],
            :attribution_suggestions => Csvarchive.get_all_as_json(current_user) } -%>
        </p>

        <p style="text-align: center; margin-top: 1.5em;">
          <%= submit_tag "Save and create data extract", :id => "archive_submit_btn", :onclick => "javascript: validateArchiveFields(true); return(false);" -%> or <%= link_to 'Cancel', csvarchives_path -%>
        </p>
      <% end -%>

    </div>
  </center>


</div>
